// 作业计划
<template>
    <f7-page class="common-page page-tab">
      <f7-navbar>
          <f7-nav-left>
              <f7-link back icon-material="chevron_left" force></f7-link>
          </f7-nav-left>
          <f7-nav-title>作业计划</f7-nav-title>
          <f7-nav-right></f7-nav-right>
      </f7-navbar>
      <van-tabs sticky>
        <van-tab name="#tab1" title="计划信息">
          <!-- 计划信息 -->
          <div id="tab1">
            <!-- 基本信息 -->
            <f7-list media-list class="search-list" v-if="models.model">
                <li v-for="(item,index) in query.tab2List1" :key="item.key+index" class="base-info qzjx-card">
                  <div class="title">
                    <span class="label">{{item.label}}</span>
                    <span class="value">{{controlData[item.key][item.key1]||'--'}}</span>
                  </div>
                  <ul class="bottom-list">
                    <li v-for="child in item.children" :key="child.key">
                      <span class="label">{{child.label}}</span>
                      <!-- <span class="value">{{controlData[item.key][child.key]||'--'}}</span> -->
                      <template v-if="child.key=='equipmentType'">
                        <span class="value">{{controlData[item.key][child.key] | DictItem(controlData.equipmentTypes)}}</span>
                      </template>
                      <template v-else>
                        <span class="value">{{controlData[item.key][child.key]||'--'}}</span>
                      </template>
                    </li>
                  </ul>
                </li>
                <li class="base-info qzjx-card">
                  <div class="title" style="margin-bottom:0">
                      <span class="label">计划{{notifyType}}日期</span>
                      <span class="value">{{models.workPlan.planTime|date('yyyy-MM-dd')}}</span>
                    </div>
                </li>
                <!-- 安装/拆卸人员 -->
                <li class="qzjx-card" v-for="(item,index) in query.tab3List" :key="item.key+index">
                  <div class="title">{{item.label}}</div>
                  <template v-if="models[item.key]&&models[item.key].length>0">
                    <div class="img-info-list" v-for="(person,personIndex) in models[item.key]" :key="'personIndex'+personIndex">
                      <img v-if="!person.personPhotoAttachId" src="../../../../assets/img/qzjx/defaultAvatar.png" alt="">
                      <img v-else :src="$util.getImgSrc(person.personPhotoAttachId)"/>
                      <div class="info-box">
                        <h3>
                          {{person.personName}}
                          <span style="color:#F37A7B;font-size: 12px;font-weight: 400;" v-if="person.isWarn">【一年内存在违章记录】</span>
                          <span style="color:#F37A7B;font-size: 12px;font-weight: 400;" v-if="person.changeOrgNum>=3">【一年内变更过{{person.changeOrgNum}}家企业】</span>
                          <span style="color:#F37A7B;font-size: 12px;font-weight: 400;" v-if="person.staffStatus=='3'">【已移除】</span>
                        </h3>
                        <div>{{person.personMobile}}</div>
                        <p>{{person.workType | DictItem(controlData.personJobTypes)}}</p>
                      </div>
                    </div>
                  </template>
                  <v-empty v-else description="暂无数据"></v-empty>
                </li>
                <li class="base-info qzjx-card">
                  <div class="title" style="margin-bottom:0">
                      <span class="label">备注</span>
                      <span class="value">{{models.model.memo||'--'}}</span>
                    </div>
                </li>
                <!-- 附件材料 -->
                <v-accordion 
                  v-for="(item,index) in list$1" 
                  :key="'list$1'+index"
                  :title="item.customName" 
                  class="qzjx-accordion"
                  :opened="true"
                >
                  <div class="p15">
                    <qm-file-list 
                      isDefaultFile
                      :defaultFiles="item.attachments"
                    ></qm-file-list>
                  </div>
                </v-accordion>
            </f7-list>
          </div>
        </van-tab>
        <van-tab name="#tab5" title="流程进度">
          <!-- 流程进度 -->
          <div id="tab5" class="p15">
            <section class="qzjx-card">
              <div class="title" style="font-size:16px;">操作记录</div>
              <v-workflow-list :data="controlData.workflow.history"></v-workflow-list>
            </section>
          </div>
        </van-tab>
      </van-tabs>
    </f7-page>
</template>

<script>
import controller from "@/libs/framework/workflowController"
import Config from "@/libs/config.js";
export default class instance extends controller {
    onBeforeInit () {
        this.urls = {
            model: "/app/equipment/eqmWorkPlan/workflow/getWorkflowViewModel",
        };
    }

    onInit () {
      this.$params.appCode = "workPlan";
    }
    onBeforeQuery (type, conditions, params) { }
    onAfterQuery (type, isSuccess, result) {
      if(result.controlData.notifyHandleType=='DIS_NOTIFY'){
        this.context.query.tab2List1[0].label='拆卸设备'
        this.context.query.tab2List1[2].label='拆卸单位'
        this.context.query.tab3List[0].label='拆卸单位技术负责人、专职安全员'
      }else{
        this.context.query.tab2List1[0].label='安装设备'
        this.context.query.tab2List1[2].label='安装单位'
        this.context.query.tab3List[0].label='安装单位技术负责人、专职安全员'
      }
      this.vm.getFileList('EQM_WORK_PLAN',result.models.model.caseId,'list$1',result.controlData.property.equipmentType)
      return result;
    }
    mixin () {
        return {
          components: {},
            data () {
                return {
                    query: {
                        tab2List1: [
                            {
                                label:'安装设备',
                                key:'property',
                                key1:'propertyCode',
                                children:[
                                  {label:'设备类型',key:'equipmentType'},
                                  {label:'产权单位',key:'enterpriseName'},
                                ]
                            },
                            {
                                label:'用于工程',
                                key:'engineeBaseInfo',
                                key1:'engineeCode',
                                children:[
                                  {label:'工程名称',key:'engineeName'},
                                  {label:'工程地址',key:'engineeAddress'},
                                ]
                            },
                            {
                                label:'安装单位',
                                key:'installOrg',
                                key1:'enterpriseName',
                                children:[
                                  {label:'统一社会信用代码',key:'creditCode'},
                                  {label:'单位地址',key:'address'},
                                ]
                            },
                        ],
                        tab3List: [
                            {
                                label:'安装单位技术负责人、专职安全员',
                                key:'directorPersonList',
                            },
                            {
                                label:'司索、司机',
                                key:'driverPersonList',
                            },
                            {
                                label:'安拆作业人员',
                                key:'installPersonList',
                            },
                        ],
                    },
                    list$1:[],
                    controlData:{
                      property:{},
                      workflow:{},
                      engineeBaseInfo:{},
                      maintenanceOrg:{},
                      installOrg:{},
                    },
                };
            },
            computed: {
                notifyType(){
                    return this.controlData.notifyHandleType=='DIS_NOTIFY'?'拆卸':'安装'
                },
            },
            methods: {
              getFileList(typeCode,dataKey,name,attachCraneType){
                this.$f7.request.post(
                  '/admin/attachmentFormDetail/listUpload', 
                  {typeCode,dataKey,attachCraneType}, 
                  (r) => {
                    r = JSON.parse(r);
                    if (r?.success&&r.parameters.fileList) {
                      this[name]=r.parameters.fileList
                      return 
                    }
                    this[name]=[]
                    this.$framework.$f7.dialog.toast("获取文件失败");
                  }
                );
              },
            },
        };
    }
}
</script>

<style lang="less" scoped>
@import url('../../../../assets/css/commonPage.less');
/deep/ .pic_upload.list .file-list{
  margin-top: 0!important;
}
</style>
